<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的消息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="../jie/index.html">
            <img src="../../res/images/logo.png" alt="layui">
        </a>
        <ul class="layui-nav fly-nav layui-hide-xs">
            <li class="layui-nav-item layui-this">
                <a href="/"><i class="iconfont icon-jiaoliu"></i>交流</a>
            </li>
            <li class="layui-nav-item">
                <a href="../case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
            </li>
            <li class="layui-nav-item">
                <a href="http://www.layui.com/" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
            </li>
        </ul>

        <div id="user_view">
            <ul class="layui-nav fly-nav-user">
                <!-- 未登入的状态 -->
                <li class="layui-nav-item">
                    <a class="iconfont icon-touxiang layui-hide-xs" href="user/login.html"></a>
                </li>
                <li class="layui-nav-item">
                    <a href="./login.html">登入</a>
                </li>
                <li class="layui-nav-item">
                    <a href="./reg.html">注册</a>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="layui-container fly-marginTop fly-user-main">
    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="user">
        <li class="layui-nav-item">
            <a href="home.html">
                <i class="layui-icon">&#xe609;</i>
                我的主页
            </a>
        </li>
        <li class="layui-nav-item">
            <a href="index.html">
                <i class="layui-icon">&#xe612;</i>
                用户中心
            </a>
        </li>
        <li class="layui-nav-item">
            <a href="set.html">
                <i class="layui-icon">&#xe620;</i>
                基本设置
            </a>
        </li>
        <li class="layui-nav-item layui-this">
            <a href="message.html">
                <i class="layui-icon">&#xe611;</i>
                我的消息
            </a>
        </li>
    </ul>

    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>

    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>


    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user" id="LAY_msg" style="margin-top: 15px;">
            <button class="layui-btn layui-btn-danger" onclick="delete_all_message()">清空全部消息</button>
            <div style="margin-top: 10px;">
                <ul class="mine-msg">
                    <div id="message_view"></div>
                </ul>
            </div>
        </div>
    </div>

</div>


<div class="fly-footer">
    <p><a href="http://fly.layui.com/" target="_blank">Fly社区</a> 2017 &copy; <a href="http://www.layui.com/"
                                                                                target="_blank">layui.com 出品</a></p>
    <p>
        <a href="http://fly.layui.com/jie/3147/" target="_blank">付费计划</a>
        <a href="http://www.layui.com/template/fly/" target="_blank">获取Fly社区模版</a>
        <a href="http://fly.layui.com/jie/2461/" target="_blank">微信公众号</a>
    </p>
</div>

<script src="../../res/layui/layui.js"></script>
<script type="text/javascript" src="../../res/jquery-1.7.2.min.js"></script>
<script id="user_tmp" type="text/html">
    <ul class="layui-nav fly-nav-user">
        <li class="layui-nav-item">
            <a class="fly-nav-avatar" href="javascript:;">
                <cite class="layui-hide-xs">{{d.username}}</cite>
                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>
                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP</i>
                <img src="{{d.headurl}}">
            </a>
            <dl class="layui-nav-child">
                <dd><a href="../user/set.html"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                <dd><a href="../user/message.html"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a>
                </dd>
                <dd><a href="../user/home.html"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a>
                </dd>
                <hr style="margin: 5px 0;">
                <dd><a onclick="logout()" style="text-align: center;cursor: pointer">退出</a></dd>
            </dl>
        </li>
    </ul>
</script>
<script id="message_tmp" type="text/html">
    {{#  layui.each(d, function(index, item){ }}
    <li>
        {{# if(item.fromtype == 1){ }}
        <blockquote class="layui-elem-quote">
            <a href="javascript:;">
                <cite>{{item.username}}</cite>
            </a>
            {{# if(item.messagetype == 1){ }}
            评论了您！！！！
            {{# } else { }}
            回复了您！！！！
            {{# } }}
            <a href="../jie/detail.html?#/id={{item.entityid}}"><cite>点击查看</cite></a>
        </blockquote>
        {{# } else { }}
        <blockquote class="layui-elem-quote">
            <a>
                <cite>系统消息：</cite>
            </a>
            <a><cite>{{}}</cite></a>
        </blockquote>
        {{# } }}
        <p>
            <span>{{item.time}}</span>
            <a href="javascript:;" class="layui-btn layui-btn-small layui-btn-danger"
               onclick="delete_message('{{item.id}}')">删除</a>
        </p>
    </li>
    {{#  }); }}
    {{#  if(d.length === 0){ }}
    <div class="fly-none">您暂时没有最新消息</div>
    {{#  } }}
</script>

<script>

    $(function () {
        user_info();
        message_info();
    })

    function user_info() {
        $.ajax(address + '/login/getUserInfoByTicket', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            layui.use('laytpl', function () {
                let laytpl = layui.laytpl;
                if (data.data != undefined) {
                    let user_view = document.getElementById("user_view");
                    let user_tmp = document.getElementById("user_tmp").innerHTML;
                    laytpl(user_tmp).render(data.data, function (html) {
                        user_view.innerHTML = html;
                    });
                    layui.use('element', function () {
                        let element = layui.element;
                        element.init();
                    });
                }
            })
        })
    }

    function message_info() {
        $.ajax(address + '/message/getMessage', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            layui.use('laytpl', function () {
                let laytpl = layui.laytpl;
                if (data.data != undefined) {
                    let message_view = document.getElementById("message_view");
                    let message_tmp = document.getElementById("message_tmp").innerHTML;
                    laytpl(message_tmp).render(data.data, function (html) {
                        message_view.innerHTML = html;
                    });
                    layui.use('element', function () {
                        let element = layui.element;
                        element.init();
                    });
                }
            })
        })
    }

    function delete_message(messageid) {

        $.ajax(address + '/message/deleteMessage', {
            type: 'POST',
            dataType: 'json',
            data: {
                'messageId': messageid
            }
        }).done(function (data) {
            if (data.code == '0') {
                layer.alert(data.message, {
                    icon: 1,
                    title: "提示"
                });
                message_info();
            } else {
                layer.alert(data.message, {
                    icon: 5,
                    title: "提示"
                });
            }
        })
    }

    function delete_all_message() {
        $.ajax(address + '/message/deleteAllMessage', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            if (data.code == '0') {
                layer.alert(data.message, {
                    icon: 1,
                    title: "提示"
                });
                message_info();
            } else {
                layer.alert(data.message, {
                    icon: 5,
                    title: "提示"
                });
            }
        })
    }

    function logout() {
        $.ajax(address + '/login/logout', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            window.location.reload()
        })
    }
</script>


</body>
</html>